home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / flex / YACCinterf < prev   
Text File  |  1995-06-28  |  1KB  |  31 lines

  1. YACC interface
  2. Previous: <User variables=>Uservariab> * Next: <Options=>Options> * Up: <Top=>!Root>
  3.  
  4. #Wrap on
  5. {fH3}Interfacing with {fCode}yacc{f}{f}
  6.  
  7. One of the main uses of {fCode}flex{f} is as a companion to the {fCode}yacc{f}
  8. parser-generator.  {fCode}yacc{f} parsers expect to call a routine
  9. named {fEmphasis}yylex(){f} to find the next input token.  The routine
  10. is supposed to return the type of the next token as well
  11. as putting any associated value in the global {fCode}yylval{f}.  To
  12. use {fCode}flex{f} with {fCode}yacc{f}, one specifies the {fEmphasis}-d{f} option to {fCode}yacc{f} to
  13. instruct it to generate the file {fCite}y.tab.h{f} containing
  14. definitions of all the {fEmphasis}%tokens{f} appearing in the {fCode}yacc{f} input.
  15. This file is then included in the {fCode}flex{f} scanner.  For
  16. example, if one of the tokens is "TOK\_NUMBER", part of the
  17. scanner might look like:
  18.  
  19. #Wrap off
  20. #fCode
  21. %\{
  22. \#include "y.tab.h"
  23. %\}
  24.  
  25. %%
  26.  
  27. [0-9]+        yylval = atoi( yytext ); return TOK\_NUMBER;
  28. #f
  29. #Wrap on
  30.  
  31.